﻿<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<html>
<head>
	<title>文档信息新增</title>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	
	<script src="../../js/scripts/boot.js" type="text/javascript"></script>
	<script src="../../js/dktp.js" type="text/javascript"></script>
	<script src="../../js/fileupload/swfupload/swfupload.js" type="text/javascript"></script>
	
	<style type="text/css">
		html, body {
			margin: 0;
			padding: 0;
			border: 0;
			width: 100%;
			height: 100%;
			overflow: hidden;
		}
	</style>
</head>
<body>

<form id="form1">
	<div style="padding-left:11px;padding-bottom:5px;">
	  	<input name="docId" id="docId" class="mini-hidden" />
	  	<input name="fileName" id="fileName" class="mini-hidden" />
		<table style="table-layout:fixed;">
			<tr>
				<td align="center" style="width:80px;">文档版本号</td>
				<td style="width:150px;">
					<input id="version" name="version"	class="mini-textbox"  required="true"/>
				</td>
				<td align="center" style="width:100px;">编辑人姓名</td>
				<td style="width:150px;">
					<input id="userName" name="userName" class="mini-textbox"/>
				</td>
			</tr>
			<tr>
				<td align="center">编辑人编号</td>
				<td><input id="userCode" name="userCode" class="mini-textbox" required="true"/></td>
				<td align="center">文档类型</td>
				<td><input name="type" id="docType" class="mini-combobox"
					 value="cn" textField="text" valueField="id" style="width: 100%; display: inline-block;" /></td>
			</tr>
			<tr>
				<td colspan="2" style="white-space: nowrap;">
	                <input id="fileupload1" class="mini-fileupload" style="width:100%"
					flashUrl="../../js/fileupload/swfupload/swfupload.swf" required="true"
					uploadUrl="/document/doc/upload.do" onuploadsuccess="onUploadSuccess"
					style="width: 80px;"
					onuploaderror="onUploadError" onfileselect="onFileSelect" />

					<a class="mini-button" onclick="startUpload" style="width:100px;">上传</a>
				</td>
			</tr>
		</table>
	</div>
    <div style="text-align:center;padding:10px;">               
           <a class="mini-button" onclick="onOk" style="width:60px;margin-right:20px;">保存</a>       
           <a class="mini-button" onclick="onCancel" style="width:60px;">取消</a>       
    </div>
</form>


	<script type="text/javascript">
		mini.parse();
		
		var userType = '<%= session.getAttribute("userType")%>';	
		var type = mini.get("docType");
		if(userType == 2) {
			type.setData([{ "id": "usa", "text": "开发进度周报" }, { "id": "cn", "text": "项目开发总结" }]);
		}else {
			type.setData([{ "id": "a", "text": "软件需求与开发计划" }, 
				{ "id": "b", "text": "可行性分析" },
				{ "id": "c", "text": "项目开发计划" },
				{ "id": "d", "text": "需求规格说明书" },
				{ "id": "e", "text": "综合测试报告" },
				{ "id": "f", "text": "软件设计说明书" },
				{ "id": "g", "text": "系统设计说明书" },
				{ "id": "h", "text": "使用说明书" }
			]);
			type.setValue("a");
		}

		
		var userCode = mini.get("userCode");
		userCode.setEnabled(false);
		userCode.setValue('<%= session.getAttribute("userId")%>');
		
		var userName = mini.get("userName");
		userName.setEnabled(false);
		userName.setValue('<%= session.getAttribute("nickName")%>');
		
        var form = new mini.Form("form1");
        var fileName = mini.get("fileName");
        function SaveData() {
            var data = form.getData();            

            form.validate();
            if (form.isValid() == false) {
            	if(!data.docId) alert("请上传文档");
            	return;
            }

           // var json = mini.encode([data]);
            $.ajax({
                url: "/document/file/saveDocFile.do",
		        type: 'post',
                data: data,
                cache: false,
                success: function (text) {
                	if(text)dktp.showTips(true,"文档新增成功");
                    CloseWindow("save");
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(jqXHR.responseText);
                    CloseWindow();
                }
            });
        }

        function CloseWindow(action) {            
            if (action == "close" && form.isChanged()) {
                if (confirm("数据被修改了，是否先保存？")) {
                    return false;
                }
            }
            if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
            else window.close();            
        }
        function onOk() {
        	SaveData();
        }
        function onCancel(e) {
            CloseWindow("cancel");
        }
        function SetData(data) {
        	if(data.action == "upload") {
                //跨页面传递的数据对象，克隆后才可以安全使用
                data = mini.clone(data);
				mini.get("docId").setValue(data.id);
				var version = mini.get("version");
				version.setValue(getNowFormatDate());
				version.setEnabled(false);
        	}  		
        }
        function GetData() {
            var o = form.getData();
            return o;
        }
		//alert("选择文件");
		function onFileSelect(e) {
		}
		function onUploadSuccess(e) {
			var data = eval('(' + e.serverData + ')');
			fileName.setValue(data.files[0].fileName);
			console.log(data);
			alert("文档上传成功");
			console.log(data.fileName)
			//this.setText("");
		}
		function onUploadError(e) {
		}
		function startUpload() {
			var fileupload = mini.get("fileupload1");
			fileupload.startUpload();
		}
		//获取当前时间
		function getNowFormatDate() {
		    var date = new Date();
		    var month = date.getMonth() + 1;
		    var strDate = date.getDate();
		    if (month >= 1 && month <= 9) {
		        month = "0" + month;
		    }
		    if (strDate >= 0 && strDate <= 9) {
		        strDate = "0" + strDate;
		    }
		    var currentdate = date.getFullYear() + month + strDate
		             + date.getHours() + date.getMinutes()
		            + date.getSeconds();
		    return currentdate;
		}
	</script>

</body>
</html>